home *** CD-ROM | disk | FTP | other *** search
- // gpibin.cpp
- #include <iostream.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include <mem.h>
- #include "gpibio.h"
-
- // INPUT CLASS FUNCTIONS
- gpibin::gpibin(int d, int b) : gpibio(b)
- {
- device = dvr[b]->open_device(d);
- }
-
- ... [full source on code disk -mb]
-
- // gin >> double
- gpibin & gpibin::operator >> (double & d)
- {
- char c;
-
- // char sure we are pointing at a valid character
- do
- c = sbumpc();
- while(!isdigit(c) && c != '-' && c!= '+' && c!= '.' && c!= 'e' && c!= 'E');
-
- // Convert input string to a double
- // via strtod which advances the char pointer
- d = strtod(gptr_-1,&gptr_);
- return *this;
- }
-
- ...
-
- // gin >> manipulator support function
- gpibin & gpibin::operator>> (gpibin & (*_f)(gpibin &))
- {
- return _f(*this);
- }
-
- // do the wait for SRQ
- int gpibin::srqwait()
- {
- char status;
- int result;
-
- ::ibwait(device,TIMO|RQS);
- if(ibsta &(TIMO|ERR))
- return (-1); // Timed out or device error
-
- // Get Serial poll information
- ::ibrsp(device,&status);
- result = status;
-
- return (result&255); // Return the last status
- }
-
- // Dummy overflow
- void gpibin::overflow()
- {
- }
-
- // Fill input stream buffer
- int gpibin::underflow()
- {
- int count,growth,inplimit;
- char *temp;
-
- // See if we have allocated a stream buffer yet
- if(base_ == NULL)
- {
- gleng_ = 128; // a good starting length
- base_ = new char[gleng_];
- if(base_ == NULL)
- {
- cerr << "Can't allocate get stream buffer." << endl;
- exit(1);
- }
- ebuf_ = base_ + gleng_;
- }
- inplimit = gleng_-1;
- // Get entire gpib transfer
- for(count=0;;)
- {
- ::ibrd(device,base_+count,inplimit);
- status = ibsta; // ibsta & ibcnt are NI globals
- count += ibcnt;
- if(status & (ERR|TIMO|END)) // Done if EOI or error
- break;
- growth = gleng_ >> 1;
- temp = new char[gleng_ + growth];
- if(temp == NULL)
- {
- cerr << "Can't increase get stream size." << endl;
- exit(1);
- }
- // transfer to new area & release old area
- memmove(temp,base_,gleng_);
- delete base_;
- base_ = temp;
- inplimit = growth-1;
- gleng_ += growth;
- }
- base_[count] = '\0';
- if(base_[count-1] == '\n')
- base_[--count] = '\0';
- gptr_ = base_;
- egptr_ = base_ + count; // Set pointer to end of get portion
- return *gptr_;
- }
-
-